fetch("http://chst.vip:1234/api/getcategorytitle")
    .then(body => body.json())
    .then(res => {
        let html = ""
        res.result.forEach(item => {
            html += `
            <div>
            <div class="title" titleid=${item.titleId}>
            <h4 titleid=${item.titleId}>
            <a titleid=${item.titleId}>
            ${item.title}
            <i class="fr" titleid=${item.titleId}>▼</i>
            </a>
            </h4>
            </div>
            <div id="container"  titleid=${item.titleId}></div>
            </div>
            `
        })
        content.innerHTML = html
        let ctns = document.querySelectorAll("#container")
        ctns = [...ctns]
        ctns.forEach(item => {
            let titleid = item.getAttribute("titleid")
            fetch("http://chst.vip:1234/api/getcategory?titleid=" + titleid)
                .then(body => body.json())
                .then(res => {
                    console.log(res);
                    let html = ""
                    res.result.forEach(item => {
                        console.log(item);
                        html += `
                        <div class="body">
                        <div class="row">
                        <div>
                        <a href="bijia.html?title=${item.category}&categoryid=${item.categoryId}">
                        ${item.category}
                        </a>
                        </div>
                        </div>
                        </div>
                        `
                    })
                    item.innerHTML = html
                        // console.log(html);
                        // // console.log(ctns);
                        // console.log(item);
                })
            let lastindex = "";
            let flag = true
            content.addEventListener('click', function(e) {
                e = e || window.event
                var target = e.target || e.srcElement
                let index = target.getAttribute("titleid")
                if (index !== lastindex || flag) {
                    for (let i = 0; i < ctns.length; i++) {
                        ctns[i].style.display = "none"
                        ctns[index].style.display = "block"
                    }
                    lastindex = index
                    flag = false
                } else {
                    for (let i = 0; i < ctns.length; i++) {
                        ctns[i].style.display = "none"
                        flag = true
                    }
                }
            })

        })
    })